package com.yuncheng.spcyApi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.yuncheng.spcyApi.constant.common.SpcyConstant;
import com.yuncheng.spcyApi.entity.SpcySqsxXptjjl;
import com.yuncheng.spcyApi.mapper.SpcySqsxXptjjlMapper;
import com.yuncheng.spcyApi.service.ISpcySqsxXptjjlService;
import com.yuncheng.spcyApi.vo.jcy.HcyXpVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.yuncheng.common.base.service.impl.BaseServiceImpl;

import java.util.Date;
import java.util.List;

/**
 * @Description: 申请事项-选派条件记录
 * @Author: yuncheng
 * @Date: 2024-03-15
 * @Version: V1.0
 */
@Service
public class SpcySqsxXptjjlServiceImpl extends BaseServiceImpl<SpcySqsxXptjjlMapper, SpcySqsxXptjjl> implements ISpcySqsxXptjjlService {

    @Override
    public List<SpcySqsxXptjjl> getXptjjlListBySqsxId(String sqsxid) {
        return list(new LambdaQueryWrapper<SpcySqsxXptjjl>()
                .eq(SpcySqsxXptjjl::getFsqsxid, sqsxid)
                .orderByDesc(SpcySqsxXptjjl::getFsxsj));
    }

    @Override
    public void initXptjjl(String fxptjid, String sqsxid, String fxpfs, HcyXpVo hcyXpVo, Integer fxzzzrs, Integer fxzzyrs, Integer fxzybrs, String fbz) {
        SpcySqsxXptjjl bean = new SpcySqsxXptjjl();
        bean.setId(fxptjid);
        bean.setFsqsxid(sqsxid);

        bean.setFxrfs(fxpfs);
        bean.setHbqy(hcyXpVo.getHbqy());
        bean.setZytc(hcyXpVo.getZytc());
        bean.setFbz(fbz);

        if (fxpfs.equals(SpcyConstant.XPFS_SDXZ)){
            bean.setFzzrs(fxzzzrs);
            bean.setFzyrs(fxzzyrs);
            bean.setFybrs(fxzybrs);

        }else {
            bean.setFzzrs(hcyXpVo.getFzzrs());
            bean.setFzyrs(hcyXpVo.getFzyrs());
            bean.setFybrs(hcyXpVo.getFybrs());
        }
        bean.setFsmszt(hcyXpVo.getFsmszt());
        bean.setFdqrdxnr(hcyXpVo.getFdqrdxnr());
        bean.setFsmssj(new Date());


        bean.setFxzzzrs(fxzzzrs);
        bean.setFxzzyrs(fxzzyrs);
        bean.setFxzybrs(fxzybrs);

        bean.setFsxsj(new Date());
        save(bean);
    }

    @Override
    public void updateXptjXzrsById(String id, int sjssk, int sjxzrs) {
        if (StringUtils.isBlank(id)){
            return;
        }
        //  0未知/1：组长/2: 组员/3：预备
        if (sjssk == 1){
            this.updateXptjXzzzrsById(id, sjxzrs);

        }else if (sjssk == 2){
            this.updateXptjXzzyrsById(id, sjxzrs);

        }else if (sjssk == 3){
            this.updateXptjXzybrsById(id, sjxzrs);

        }
    }

    @Override
    public void updateXptjXzzzrsById(String id, Integer fxzzzrs) {
        if (StringUtils.isBlank(id)){
            return;
        }
        LambdaUpdateWrapper<SpcySqsxXptjjl> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(SpcySqsxXptjjl::getId, id);

        SpcySqsxXptjjl updateBean = new SpcySqsxXptjjl();
        updateBean.setFxzzzrs(fxzzzrs);

        update(updateBean, updateWrapper);
    }

    @Override
    public void updateXptjXzzyrsById(String id, Integer fxzzyrs) {
        if (StringUtils.isBlank(id)){
            return;
        }

        LambdaUpdateWrapper<SpcySqsxXptjjl> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(SpcySqsxXptjjl::getId, id);

        SpcySqsxXptjjl updateBean = new SpcySqsxXptjjl();
        updateBean.setFxzzyrs(fxzzyrs);

        update(updateBean, updateWrapper);
    }

    @Override
    public void updateXptjXzybrsById(String id, Integer fxzybrs) {
        if (StringUtils.isBlank(id)){
            return;
        }

        LambdaUpdateWrapper<SpcySqsxXptjjl> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(SpcySqsxXptjjl::getId, id);

        SpcySqsxXptjjl updateBean = new SpcySqsxXptjjl();
        updateBean.setFxzybrs(fxzybrs);

        update(updateBean, updateWrapper);
    }
}
